package com.FoodDemo2;

import java.util.ArrayList;
import java.util.Scanner;

public class FoodManager {
    private ArrayList<com.cals.FoodDemo2.Food> foods = new ArrayList<>();
    Scanner sc = new Scanner(System.in);//全局扫描器

    //添加菜品
    public void addFood() {
        System.out.println("===新菜品上架===");
        com.cals.FoodDemo2.Food food = new com.cals.FoodDemo2.Food();
        System.out.println("请输入你要添加菜品的名称");
        String name = sc.next();
        food.setName(name);

        System.out.println("请输入你要添加菜品的价格");
        double originalprice = sc.nextDouble();
        food.setOriginprice(originalprice);

        System.out.println("请输入你要添加菜品的优惠价格");
        double specialprice = sc.nextDouble();
        food.setSoeciaprice(specialprice);

        System.out.println("请输入你要添加菜品的其他信息");
        String info = sc.next();
        food.setInfo(info);

        //把菜品添ArrayList列表里面
        foods.add(food);
    }

    //展示所有的菜品
    public void showFood() {
        for (int i = 0; i < foods.size(); i++) {
            com.cals.FoodDemo2.Food foodshow = foods.get(i);
            System.out.println("菜品名称：" + foodshow.getName());
            System.out.println("菜品价格：" + foodshow.getOriginprice());
            System.out.println("菜品优惠价格：" + foodshow.getSoeciaprice());
            System.out.println("菜品其他信息：" + foodshow.getInfo());
        }
    }

    //删除一个菜品
    public void deleteFood() {

        System.out.println("请输入你要删除菜品的名字：");
        String delname = sc.next();
        for (int i = 0; i < foods.size(); i++) {
            com.cals.FoodDemo2.Food delnamefood = foods.get(i);
            if (delnamefood.getName().equals(delname)) {
                foods.remove(delnamefood);
            }
        }
        System.out.println("你要删除的菜品不存在！");
    }


    //修改单个菜品里面的指定信息
    public void resetFood() {
        System.out.println("请输入你要更改的菜品名字：");
        String resetname = sc.next();
        for (int i = 0; i < foods.size(); i++) {
            com.cals.FoodDemo2.Food resetFood = foods.get(i);

            if (resetFood.getName().equals(resetname)) {
                System.out.println("请输入你要改的选项：name、originprice、soeciaprice、info、exitreste");
                String restemodel = sc.next();
                switch (restemodel) {
                    case "name":
                        System.out.println("请输入要把name改为什么：");
                        String stenameinfo = sc.next();
                        foods.get(i).setName(stenameinfo);
                        break;
                    case "originprice":
                        System.out.println("请输入要把originprice改为什么：");
                        double setorpriceinfo = sc.nextDouble();
                        foods.get(i).setSoeciaprice(setorpriceinfo);
                        break;
                    case "soeciaprice":
                        System.out.println("请输入要把soeciaprice改为什么：");
                        double setsopriceinfo = sc.nextDouble();
                        foods.get(i).setSoeciaprice(setsopriceinfo);
                        break;
                    case "info":
                        System.out.println("请输入要把info改为什么：");
                        String setinfoinfo = sc.next();
                        foods.get(i).setInfo(setinfoinfo);
                        break;
                    case "exitreste":
                        return;
                    default:
                        System.out.println("输入命令有误!");

                }
            }
        }
    }

    //启动系统
    public void start() {
        while (true) {
            System.out.println("===欢迎进入系统===");
            System.out.println("请输入要执行的命令：");
            System.out.println("1、添加菜品（add）");
            System.out.println("2、展示菜品（show）");
            System.out.println("3、删除菜品（del）");
            System.out.println("4、修改菜品信息（reset）");
            System.out.println("5、推出高于程序（exit）");
            String contro = sc.next();
            switch (contro) {
                case "add":
                    addFood();
                    break;
                case "show":
                    showFood();
                    break;
                case "del":
                    deleteFood();
                    break;
                case "reset":
                    resetFood();
                    break;
                case "exit":
                    return;
                default:
                    System.out.println("你输入的命令有误！");
            }
        }
    }
}
